package com.java2207.group1.util;

import java.util.Calendar;
import java.util.Date;

/**
 * @author HuiCL
 * @version 1.0
 * @date 2022/7/26 9:42
 */
public class SameDayUtil {
    /**
     * 判断两个日期是否是同一天
     * @param date1 第一个日期
     * @param date2 第二个日期
     * @return 是同一天则返回true, 不是则返回false
     */
    public static boolean isSameDay(Date date1, Date date2) {
        Calendar cal1 = Calendar.getInstance();
        Calendar cal2 = Calendar.getInstance();

        cal1.setTime(date1);
        cal2.setTime(date2);

        boolean sameDay = cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
                cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR);

        return sameDay;
    }
}
